<template>
  <div class="login-container">
    <div class="login_box">
      <div class="asicon">
        <img src="../../assets/logo.png">
      </div>
      <el-form :model="loginForm" :rules="rules" ref="AdminLoginFormref" label-width="0px" class="login_form">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="iconfont icon-user"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="iconfont icon-lock_fill" type="password"></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="Alogin" class="btn_par">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "Alogin",
  data(){
    return{
      loginForm:{
        username:'admin',
        password:'123456'
      },
      rules:{
        username:[{required:true,message:'请输入用户名',trigger:'blur'},
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [{required:true,message:'密码不能为空',trigger:'blur'}]
      }

    }
  },
  methods:{
    reset(){
      this.$refs.AdminLoginFormref.resetFields();
    },
    Alogin(){
      this.$refs.AdminLoginFormref.validate(async valid=>{
          if(valid){
            const res=await this.$http.post('/admin/login/login',this.loginForm)
            if(res.data.status!==200){this.$message.error('登录失败')
            }else{
              this.$message.success('登录成功')
              window.sessionStorage.setItem('token',res.data.data.token)
              this.$router.push("./admin/index")
            }
          }
        }

      )
    }
  }
}
</script>

<style lang="less" scoped>
.login-container{
  background: #2c3e50;
  height: 100%;
}
.login_box{
  width: 450px;
  height: 300px;
  background: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}
.asicon{
  width: 130px;
  height: 130px;
  padding: 5px;
  border-radius: 50%;
  border: 1px solid #eeeeee;
  position: absolute;
  left: 50%;
  transform: translate(-50%,-50%);
  background: #fff;
  img{
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #f0f0f0;
  }
}
.login_form{
  width: 100%;
  position: absolute;
  bottom: 0;
  padding: 0 20px;
  box-sizing: border-box;
}
.btns{
  text-align: center;
}
.btn_par{
  width: 100%;
}
</style>
